1. /* slmput.cpp by K.Tsuru */
  2. // function ID = 204, 261 DARDIX
  3. /***************
  4. SLong class
  5. output
  6. ****************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. static int putcr(int cr, FILE* out){
  11. if(cr) putc('\n', out);
  12. return cr ? 1 : 0;
  13. }
  14. static int putdelmt(int d, FILE* out){
  15. if(d) putc(d, out);
  16. return d ? 1 : 0;
  17. }
  18. /*
  19. It returns n-th digit by a character. n = 0 for first position
  20. For continuously picking out a static array buff[] is used.
  21. */
  22. int SLong::CharNthFig(long n) const{
  23. static int pos = -1;
  24. static char buff[DFIGURES+1];
  25. int p, r;
  26. if(n < 0){ pos = -1; return 0; } //initialize
  27. p = int(n/DFIGURES); //There is in figure[p].
  28. r = int(n%DFIGURES); //r-th position in figure[p].
  29. if(p != pos){ //renew buff[] and pos
  30. pos = p;
  31. fType f = figure(p);
  32. for(int j = 0; j < DFIGURES; j++){//pack into buff[] in reverse order
  33. buff[j] = '0' + f%10; // f = 1234 --> buff[] = "4321"
  34. f /= 10;
  35. }
  36. }
  37. return (int)buff[r];
  38. }
  39. /*
  40. main body, usage : x.Put()
  41. */
  42. long SLong::Put(long fU, int pL, int cl, int dm) const{
  43. if(fU > 0) {
  44. figUnit = fU; perLine = pL; lineFormat = cl; delmt = dm; // copy to static variable
  45. } else if(fU == 0){ fU = LONG_MAX; delmt = 0; }
  46. SignCheck(204); // sign == UNDECIDED ?
  47. FILE* out = FileStream();
  48. SLong temp(*this);
  49. ioCount=0; //counter for output characters
  50. long f = temp.DFigures();
  51. long numCount = f; //counter for output digits
  52. int uCount = 0; //counter for 'fig' figures
  53. long lunit = perLine ? perLine : (displayWidth+1)/(fU+1); //units per line
  54. if(temp.Sign(204) == 0){ putc('0', out); ioCount++; goto Ret; }
  55. if(!lunit) lunit = 1;
  56. //output negative sign
  57. if( Sign(204) == -1 ){ putc('-', out); ioCount++; }
  58. //integral part
  59. temp.CharNthFig(-1L);
  60. while(1){
  61. putc( temp.CharNthFig(numCount -1), out );
  62. numCount--; ioCount++;
  63. if(!numCount) break;
  64. if( !(numCount % fU) ) { //output one unit
  65. uCount++;
  66. if(!(uCount % lunit)){ //reach the end of line
  67. if(delmt != ' ') ioCount += putdelmt(delmt, out);
  68. if(lineFormat & CONTINUE){ putc('\\', out); ioCount++; }
  69. if(lineFormat & CRLF){ putc('\n', out); ioCount++; }
  70. if(lineFormat == NO_CR) ioCount += putdelmt(delmt, out);
  71. } else ioCount += putdelmt(delmt, out);
  72. }
  73. }
  74. Ret:
  75. ioCount += putcr( lineFormat & END_CR, out );
  76. return --ioCount; //It does not output a delimiter at the end.
  77. }

slmput.cpp : last modifiled at 2017/07/17 16:56:41(2,435 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).